*** This Do-File replicates all figures and tables from the article
***	Vertrauen in politische Entscheidungsträger:innen und das politische System im Allgemeinen während des ersten Jahres der Corona-Pandemie in Deutschland, in GWP
*** Sebastian Jäckle & Uwe Wagschal 


clear all
version 14.2

* additional packages (need to be loaded only if not already exist)
* ssc install outreg2, replace
* ssc install estout, replace
* ssc install coefplot, replace
* ssc install splitvallabels
* ssc install blindschemes, replace
* ssc install interflex, replace
* ssc install mivif, replace
findit  mcartest
findit mibeta


* Here you need to set your path to the "analysis"-folder
 cd "YOUR_PATH\replication"



* Load dataset waves 1-3

use "data\PPDdata_corona.dta"


* change missing codes 0 --> .

	mvdecode v_363, 	mv(0)
	mvdecode v_364,		mv(0)
	mvdecode v_365,		mv(0)
	mvdecode v_366,		mv(0)
	mvdecode v_368,		mv(0)
	mvdecode v_369,		mv(0)
	mvdecode v_370,		mv(0)
	mvdecode v_371,		mv(0)
	mvdecode v_372,		mv(0)
	mvdecode v_374,		mv(0)
	mvdecode v_217,		mv(0)
	mvdecode v_144,		mv(0)
	mvdecode v_145,		mv(0)
	mvdecode v_484,		mv(0)
	mvdecode v_486,		mv(0)
	mvdecode v_488,		mv(0)
	mvdecode v_490,		mv(0)
	mvdecode v_491,		mv(0)
	mvdecode v_492,		mv(0)
	mvdecode v_493,		mv(0)
	mvdecode v_494,		mv(0)
	mvdecode v_495,		mv(0)
	mvdecode v_553,		mv(0)
	mvdecode v_554,		mv(0)
	mvdecode v_556,		mv(0)
	mvdecode v_557,		mv(0)
	mvdecode v_344,		mv(0)
	mvdecode v_767,		mv(0)
	mvdecode v_768,		mv(0)
	mvdecode v_774,		mv(0)
	mvdecode v_770,		mv(0)
	mvdecode v_775,		mv(0)
	mvdecode v_389,		mv(0)
	mvdecode v_42, 		mv(0)
	mvdecode v_342,	 	mv(0)
	mvdecode v_498, 	mv(0)
	mvdecode v_502_a, 	mv(0)
	mvdecode geschlecht,mv(0)	
	mvdecode v_505, 	mv(0)
	mvdecode v_167,		mv(0)
	mvdecode v_172,		mv(0)
	mvdecode v_173,		mv(0)
	mvdecode f3_1l,		mv(0)	
	mvdecode f3_2l,		mv(0)
	mvdecode f3_3l,		mv(0)
	mvdecode f3_4l,		mv(0)
	mvdecode f3_5l,		mv(0)
	mvdecode f3_7l,		mv(0)
	mvdecode v_170,		mv(0)
	mvdecode v_171,		mv(0)
	mvdecode v_267, 	mv(0)
	mvdecode v_230, 	mv(0)
	mvdecode v_231, 	mv(0)
	mvdecode v_232, 	mv(0)
	mvdecode v_233, 	mv(0)
	mvdecode v_375,		mv(0)
	mvdecode v_376,		mv(0)
	mvdecode v_377,		mv(0)
	mvdecode v_378,		mv(0)
	mvdecode v_379,		mv(0)

	replace bundesland = . if bundesland == 0
	replace bundesland = . if bundesland == 17

* gender including non-binary
	gen gender = geschlecht

	* gender (including non-binary)
	label define gender 1 "male" 2 "female" 3 "non-binary" 
	label values gender gender	
	
* gender = non-binary --> .
	mvdecode geschlecht, mv(3)

	* male
	tab geschlecht, gen(n)
	rename n1 male
	label define male 0 "female" 1 "male"
	label value male male	
	
* still at school --> .
	mvdecode v_505, mv(1)

*** Dependent Variable Political Trust (specific trust & diffuse trust)

	* precheck for index construction
	pwcorr v_363 - v_371, obs sig
	factor v_363 - v_371
	rotate
	estat kmo
	alpha v_363 - v_371, item
	
	* specific trust in Government, chancelor, Bundestag, prime minister land
	alpha v_363 v_364 v_368 v_370, item
	gen spectrust = (v_363 + v_364 + v_368 + v_370)/4
	
	* diffuse trust in political system
	alpha v_365 v_366 v_369 v_371, item
	factor v_365 v_366 v_369 v_371
	rotate
	estat kmo
	gen difftrust = (v_365 + v_366 + v_369 + v_371)/4
	
*** Independent Variables	
	
	* acceptance of anti-Covid-19 measures 
	* precheck for index construction
	pwcorr v_484 - v_495, obs sig
	factor v_484 - v_495
	rotate
	estat kmo
	alpha v_484 - v_495, item
	gen covid19_measures = (v_486 + v_488 + v_490 + v_491 + v_492 + v_493 + v_494 + v_495)/8
	
	* evaluation of actual government measures (-4: completely against government measures; + 4 completely in favor of government measures)
	* precheck for index construction
	pwcorr v_553 v_554 v_556 v_557, obs sig
	factor v_553 v_554 v_556 v_557
	rotate
	estat kmo
	alpha v_553 v_554 v_556 v_557, item
	gen govmeasures = (v_553 + v_554)/2 - (v_556 + v_557)/2
	
	* biggest fear
	gen biggest_fear = .
	replace biggest_fear = 1 if v_152 == 1
	replace biggest_fear = 2 if v_153 == 1
	replace biggest_fear = 3 if v_154 == 1
	replace biggest_fear = 4 if v_155 == 1
	replace biggest_fear = 5 if v_156 == 1
	replace biggest_fear = 6 if v_157 == 1
    label define biggest_fear 1 "unemployment" 2 "illness" 3 "economic crash" 4 "restrictions of lifestyle habits" 5 "restrictions of democratic rights" 6 "loneliness"
	label value biggest_fear biggest_fear	
	
	* Mediatrust (classic media & social media + Difference between the two)
	recode f3_1l (1=1) (2=0.5) (3=0), gen(mt_newspapers)
	recode f3_2l (1=1) (2=0.5) (3=0), gen(mt_socialmedia)
	recode f3_3l (1=1) (2=0.5) (3=0), gen(mt_privatetv)
	recode f3_4l (1=1) (2=0.5) (3=0), gen(mt_blogsyoutube)
	recode f3_5l (1=1) (2=0.5) (3=0), gen(mt_magazine)
	recode f3_6l (1=1) (2=0.5) (3=0), gen(mt_onlinemedia)
	recode f3_7l (1=1) (2=0.5) (3=0), gen(mt_radio)
	recode v_170 (1=1) (2=0.5) (3=0), gen(mt_publicbroadcast)
	recode v_171 (1=1) (2=0.5) (3=0), gen(mt_official)

	alpha mt_news mt_private mt_magazine mt_radio mt_public mt_official mt_onlinemedia, item 
		* --> exclude private tv from the scale
	gen mediatrust_classic = (mt_news + mt_magaz + mt_radio + mt_public + mt_offic + mt_onlinemedia)/6
	
	
	alpha mt_blogsyoutube mt_socialmedia 
	gen mediatrust_socialmedia = (mt_socialmedia + mt_blogsyoutube)/2
	gen dif_mediatrust = mediatrust_classic - mediatrust_socialmedia
	
	* incomeloss
	recode v_172 (1=5) (2=4) (3=3) (4=2) (5=1), gen(incomenow)
	label define incomenow 1 "find it very difficult to make ends meet" 5 "can live very comfortably on the income"
	label value incomenow incomenow
	recode v_173 (1=5) (2=4) (3=3) (4=2) (5=1), gen(incomebefore)
	label define incomebefore 1 "find it very difficult to make ends meet" 5 "can live very comfortably on the income"
	label value incomebefore incomevefore
	gen incomeloss = incomebefore-incomenow
	
	* age
	gen age = 2020 - v_496
	
	* highest educational attainment
	recode v_505 (2/3=1)(4=2)(5=3) (6=4) (7=5), gen (v_505_a)
	label define edu 1 "Schulabbruch & Hauptschulabschluss (ISCED 2)" 2 "Mittlere Reife (ISCED 2)" 3 "Fachhochschulreife (ISCED 3)" 4 "Abitur (ISCED 3)" 5 "Hochschulabschluss (ISCED 5a)"
	label value v_505_a edu
	
	tab v_505_a, gen(p)
	rename p1 ohne_hauptschule
	rename p2 mittlere_reife
	rename p3 fachhochschulreife
	rename p4 abitur
	rename p5 studium
	
	* healthstate
	recode v_498 (1=5) (2=4) (3=3) (4=2) (5=1), gen(healthstate)
	label define healthstate 1 "very bad" 5 "very good"
	label value healthstate healthstate
	
	* links-rechts 0-1
	gen links_rechts = (v_42 -1)/10
	
	* political extremism (0 = middle category, 5 = most extreme)
	gen pol_extr = abs(6-v_42)
	table pol_extr
	
	* householdsize 3+
	recode v_502_a (1/2=0) (3/34=1), gen(hh3andmore)
	label define hh3andmore 0 "householdsize < 3" 1 "householdsize >= 3"
	label values hh3andmore hh3andmore
	
	* children in household (only asked in wave 2 & wave 3) 
	recode v_230 (1=0) (2=1) (3=2) (4=3), gen(children_0_2)
	recode v_231 (1=0) (2=1) (3=2) (4=3), gen(children_3_6)
	recode v_232 (1=0) (2=1) (3=2) (4=3), gen(children_7_10)
	recode v_233 (1=0) (2=1) (3=2) (4=3), gen(children_11_18)
	
	egen children_total = rowtotal(children_0_2  children_3_6  children_7_10  children_11_18)
		* children small: (0-10)
	egen children_small = rowtotal(children_0_2  children_3_6  children_7_10)
		* both children variables in wave 1 --> NA
	replace children_total = . if welle ==1
	replace children_small = . if welle ==1
	 
	
	* authoritarianism
		* precheck for index construction
	pwcorr v_375-v_379, obs sig
	factor v_375-v_379
	rotate
	estat kmo
	alpha v_375-v_379, item 
		* index using the mean of the five authoritarianism questions
	gen auth = (v_375 + v_376 + v_377 + v_378 + v_379)/5
	
	* voting intention
	label define vote_intent 1 "CDU/CSU" 2 "SPD" 3 "Linke" 4 "Grüne" 5 "FDP" 6 "AfD" 7 "Sonstige" 8 "Würde nicht wählen" 9 "Nicht wahlberechtigt"
	label values v_167 vote_intent

	* voting intention incl. protest_party
	gen vot_int = v_167
	replace vot_int = 10 if v_167 == 9
	replace vot_int = 9 if v_167 == 8
	replace vot_int = 8 if v_167 == 7
	replace vot_int = 7 if v_168 == "Alternative Partei die mit den Altoarteien abrechnet"
	replace vot_int = 7 if v_168 == "Aus Protest, nicht aus Überzeugung"
	replace vot_int = 7 if v_168 == "Basis"
	replace vot_int = 7 if v_168 == "Basis Demokraten"
replace vot_int = 7 if v_168 == "Basis Partei"
replace vot_int = 7 if v_168 == "Basis demokratische Partei"
replace vot_int = 7 if v_168 == "Basis-Partei"
replace vot_int = 7 if v_168 == "Basisdemikratische Partei"
replace vot_int = 7 if v_168 == "Basisdemokratische Partei Deutschland"
replace vot_int = 7 if v_168 == "Basisdemokratische Partei Deutschland   Kurzform - dieBasis"
replace vot_int = 7 if v_168 == "Basisdemokratische Partei Deutschland, dieBasis"
replace vot_int = 7 if v_168 == "Basisdemokratische Partei Deutschlands"
replace vot_int = 7 if v_168 == "Basispartei"
replace vot_int = 7 if v_168 == "DIE BASIS"
replace vot_int = 7 if v_168 == "Die Baisis"
replace vot_int = 7 if v_168 == "Die Basis"
replace vot_int = 7 if v_168 == "Die Basis (Basisdemokratische Partei Deutschland)"
replace vot_int = 7 if v_168 == "Die Basis oder andere zB wir2020"
replace vot_int = 7 if v_168 == "Die Basisdemokratische Partei Deutschland"
replace vot_int = 7 if v_168 == "Die basis"
replace vot_int = 7 if v_168 == "Die basisdemokratische Partei Deutschland"
replace vot_int = 7 if v_168 == "DieBasis"
replace vot_int = 7 if v_168 == "Eine Partei die sinnvoller mit der Krise umgeht."
replace vot_int = 7 if v_168 == "Eine andere Partei - zb. Widerstand2020"
replace vot_int = 7 if v_168 == "Eine sich aus der Krise entwickelnde neue partei"
replace vot_int = 7 if v_168 == "Erst immer ,,Freie Wähler  , sobald jetzt Wahlen wären, ,, Widerstand2020"
replace vot_int = 7 if v_168 == "Protestpartei"
replace vot_int = 7 if v_168 == "Protestwahl / ungültige Stimme"
replace vot_int = 7 if v_168 == "Protestwahl je nachdem, welche Partei(en) zugelassen sind"
replace vot_int = 7 if v_168 == "Protestwähler"
replace vot_int = 7 if v_168 == "Querdenker, sofern sie antreten"
replace vot_int = 7 if v_168 == "WID 2020"
replace vot_int = 7 if v_168 == "WIDERSTAND 2020"
replace vot_int = 7 if v_168 == "WIR 2020"
replace vot_int = 7 if v_168 == "WIR Partei"
replace vot_int = 7 if v_168 == "WIR, Querdenkerliste"
replace vot_int = 7 if v_168 == "WIR2020"
replace vot_int = 7 if v_168 == "Widerstand 2020"
replace vot_int = 7 if v_168 == "Widerstand 2020 oder eine andere möglichst direktdemokratische Partei"
replace vot_int = 7 if v_168 == "Widerstand 202ü"
replace vot_int = 7 if v_168 == "Widerstand d2020"
replace vot_int = 7 if v_168 == "Widerstand/Wir2020"
replace vot_int = 7 if v_168 == "Widerstand20"
replace vot_int = 7 if v_168 == "Widerstand2000"
replace vot_int = 7 if v_168 == "Widerstand2020"
replace vot_int = 7 if v_168 == "Widerstand2020 Deutschland"
replace vot_int = 7 if v_168 == "Widerstand2020 das Original"
replace vot_int = 7 if v_168 == "Widerstand2020/WIR2020"
replace vot_int = 7 if v_168 == "Widerstand2029"
replace vot_int = 7 if v_168 == "Widerstandspartei"
replace vot_int = 7 if v_168 == "Widerstandspartei 2020"
replace vot_int = 7 if v_168 == "Widestand2020"
replace vot_int = 7 if v_168 == "Widetstand2020"
replace vot_int = 7 if v_168 == "Wiederstand 2020"
replace vot_int = 7 if v_168 == "Wiederstand2020"
replace vot_int = 7 if v_168 == "Wir 2020"
replace vot_int = 7 if v_168 == "Wir 2020 oder die Partei"
replace vot_int = 7 if v_168 == "Wir2020"
replace vot_int = 7 if v_168 == "Wir2020 oder die Basis"
replace vot_int = 7 if v_168 == "Wir2020-partei"
replace vot_int = 7 if v_168 == "die Basis"
replace vot_int = 7 if v_168 == "die aus der/den neuen Bewegung/en kommen wird"
replace vot_int = 7 if v_168 == "die basis"
replace vot_int = 7 if v_168 == "die hoffentlich noch kommt und den Wahnsinn stoppt!"
replace vot_int = 7 if v_168 == "dieBasis"
replace vot_int = 7 if v_168 == "dieBasis-Partei"
replace vot_int = 7 if v_168 == "evtl. Wir2020"
replace vot_int = 7 if v_168 == "querdenken 21"
replace vot_int = 7 if v_168 == "widerstand 2020"
replace vot_int = 7 if v_168 == "widerstand2020"
replace vot_int = 7 if v_168 == "wiederstand 2020"
replace vot_int = 7 if v_168 == "wiederstand20202"
replace vot_int = 7 if v_168 == "wir"
replace vot_int = 7 if v_168 == "wir 2020"
replace vot_int = 7 if v_168 == "wir2020"
replace vot_int = 7 if v_168 == "wir2020-Partei"
replace vot_int = 7 if v_168 == "zb (aber nicht zwingend) Widerstand2020"
replace vot_int = . if vot_int == .b
	
	label define vote_intent2 1 "CDU/CSU" 2 "SPD" 3 "Linke" 4 "Grüne" 5 "FDP" 6 "AfD" 7 "Protestpartei" 8 "Sonstige" 9 "Würde nicht wählen" 10 "Nicht wahlberechtigt"
	label values vot_int vote_intent2	
	
* level 2 variables
	
	* GDP per capita
	gen gdp_pc_17 = bip_17/bev_17
	
	* number of infections last seven days per 100,000 inhabitants
		* absolute number of infections in last 7 days
	egen inf_7day_abs = rowtotal(inf_7tage_w1 inf_7tage_w2 inf_7tage_w3) , missing
	gen inf_7day_rel = inf_7day_abs / bev_18 * 100000
	
	* number of deaths during last months 30 days per 100,000 inhabitants
		* absolute number of deaths in last 30 days
	egen tot_30day_abs = rowtotal(tot_30tage_w1 tot_30tage_w2 tot_30tage_w3) , missing
	gen tot_30day_rel = tot_30day_abs / bev_18 * 100000
	
	
		
* label variables
	label variable spectrust 				"Specific political trust"
	label variable difftrust				"Diffuse political trust"
	label variable v_344 					"Social trust"
	label variable covid19_measures			"Acceptance of Covid-19 measures"
	label variable govmeasures				"Evaluation of actual government measures"
	label variable biggest_fear				"Biggest fear"
	label variable mediatrust_classic		"Trust in traditional media"
	label variable mediatrust_socialmedia	"Trust in social media"
	label variable dif_mediatrust			"Difference trust in traditional vs. social media"
	label variable auth						"Authoritarianism"
	label variable pol_extr					"Ideological extremism"
	label variable children_total			"Number of children in household (0-18 years)"
	label variable children_small			"Number of children in household (0-10 years)"
	label variable links_rechts 					"Left = 1; Right = 11"
	label variable v_167					"Voting intention"
	label variable vot_int					"Voting intention"
	label variable v_342					"Political interest"
	label variable healthstate 				"Overall health status"
	label variable incomeloss				"Loss of income"
	label variable hh3andmore				"Household 3+ (dummy)"
	label variable male						"Male"
	label variable gender					"Gender"
	label variable age						"Age"
	label variable v_144					"Strain due to Covid-19"
	label variable v_145					"Financial impact of Covid-19"
	label variable v_505_a					"Highest educational attainment"

	label variable ohne_hauptschule 		"School dropout/Hauptschulabschluss (ISCED 2)"
	label variable mittlere_reife			"Mittlere Reife (ISCED 2)"
	label variable fachhochschulreife  		"Fachhochschulreife (ISCED 3)"
	label variable abitur 					"Abitur (ISCED 3)"
	label variable studium					"University degree (ISCED 5a)"
	label variable inf_7day_rel				"# Covid-19 cases last 7 days"
	label variable tot_30day_rel			"# Covid-19 deaths last 30 days"
	label variable alq_18					"Unemployment rate (2018)"
	label variable alq_19					"Unemployment rate (2019)"
	label variable gdp_pc_17				"GDP per capita (2017)"

	
* keep variables 
	#delimit ;
	keep 	spectrust	
			difftrust				
			v_344
			covid19_measures
			govmeasures
			biggest_fear
			mediatrust_classic
			mediatrust_socialmedia
			dif_mediatrust
			auth
			pol_extr
			children_total
			children_small
			links_rechts					
			v_167
			vot_int
			v_342					
			healthstate				
			incomeloss				
			hh3andmore				
			male
			gender
			age		
			v_144
			v_145
			v_505_a	
			ohne_hauptschule		
			mittlere_reife			
			fachhochschulreife		
			abitur					
			studium			
			inf_7day_rel
			tot_30day_rel
			alq_18					
			alq_19					
			gdp_pc_17
			NUTS3 
			bundesland
			welle
			id_alle_3_wellen
			id_1_und_2
			id_2_und_3
			id_1_und_3
			id_welle1
			id_welle2
			id_welle3
			id_all;
			#delimit cr

* replace .b --> .
	recode gender 		(.b = .)
	recode v_342		(.b = .)
	recode v_344		(.b = .)
	recode links_rechts			(.b = .)	
	recode v_167		(.b = .)
	recode v_505_a		(.b = .)
	recode healthstate	(.b = .)	
	recode hh3andmore	(.b = .)	
	recode v_144		(.b = .)
	recode v_145		(.b = .)
	recode bundesland	(.b = .)
	
* number of children from wave2 --> wave 1	
	* save as working dataset
	save "dump\corona_panel_working.dta", replace

	* keep only wave 1 (only those existent in wave 1 and 2)  
	keep if welle == 1
	drop if id_1_und_2 == .
	drop  children_total children_small
	save "dump\corona_panel_working_w1a.dta", replace
	
	clear all
	use "dump\corona_panel_working.dta"
	
	* keep only wave 1 (only those not in wave 2)
	keep if welle == 1
	drop if id_1_und_2 != .
	save "dump\corona_panel_working_w1b.dta", replace
	
	clear all
	use "dump\corona_panel_working.dta"
	
	* keep only wave 2 (only those existent in wave 1 and 2) 
	keep if welle == 2	
	drop if id_1_und_2 ==.
	save "dump\corona_panel_working_w2a.dta", replace
	
	clear all
	use "dump\corona_panel_working.dta"

	* keep only wave 2 (only those not in wave 1 and 2) 
	keep if welle == 2	
	drop if id_1_und_2 !=.
	save "dump\corona_panel_working_w2b.dta", replace
	
	clear all
	use "dump\corona_panel_working.dta"	
	
	* keep only wave 3
	keep if welle == 3	
	save "dump\corona_panel_working_w3.dta", replace
	
	* merge children from wave2 to wave1
	clear all
	use "dump\corona_panel_working_w1a.dta"
	merge 1:1 id_1_und_2 using "dump\corona_panel_working_w2a.dta", keepusing(children_total children_small) 
	save "dump\corona_panel_working_w1a_children.dta", replace
	
	append using "dump\corona_panel_working_w1b.dta"
	append using "dump\corona_panel_working_w2a.dta"
	append using "dump\corona_panel_working_w2b.dta"
	append using "dump\corona_panel_working_w3.dta"
	drop _merge
	save "dump\corona_panel_working_final.dta", replace
	
	label variable age Alter
	label define gender 1 "männlich" 2 "weiblich" 3 "divers", replace
	label values gender gender

* Distribution of main demographic variables in the sample
	
	* figure not in article
	set scheme plottig
	
	* Gender
	graph bar if welle == 1, over(gender) note("N=8.106") ytitle("")
	graph save "dump/gender_w1.gph", replace
	graph bar if welle == 2, over(gender) note("N=6.851") ytitle("")
	graph save "dump/gender_w2.gph", replace
	graph bar if welle == 3, over(gender) note("N=5.707") ytitle("")
	graph save "dump/gender_w3.gph", replace
		
	* Age
	hist age if welle == 1, note("N=8.052") ytitle("")
	graph save "dump/age_w1.gph", replace
	hist age if welle == 2, note("N=6.797") ytitle("")
	graph save "dump/age_w2.gph", replace
	hist age if welle == 3, note("N=5.705") ytitle("")
	graph save "dump/age_w3.gph", replace

	* Education
	splitvallabels v_505_a , length(19)
	graph bar if welle == 1, over(v_505_a,  relabel(`r(relabel)')  label(angle(90))) note("N=8.018") ytitle("")
	graph save  "dump/edu_w1.gph", replace
	splitvallabels v_505_a , length(20)
	graph bar if welle == 2, over(v_505_a,  relabel(`r(relabel)')  label(angle(90))) note("N=6.781") ytitle("")
	graph save  "dump/edu_w2.gph", replace
	splitvallabels v_505_a , length(20)
	graph bar if welle == 3, over(v_505_a,  relabel(`r(relabel)')  label(angle(90))) note("N=5.669") ytitle("")
	graph save  "dump/edu_w3.gph", replace
	
	* Party
	graph bar if welle == 1, over(vot_int, label(angle(30))) note("N=8.006")
	graph save "dump/vote_w1.gph", replace
	graph bar if welle == 2, over(vot_int, label(angle(30))) note("N=6.721")
	graph save "dump/vote_w2.gph", replace
	graph bar if welle == 3, over(vot_int, label(angle(30))) note("N=5.622")
	graph save "dump/vote_w3.gph", replace
	
	* grafik zusammensetzen
	graph combine "dump/gender_w1.gph" "dump/age_w1.gph" "dump/edu_w1.gph" "dump/vote_w1.gph", title (Welle 1 Mai 2020) rows(4)
	graph save "dump/dist_w1.gph", replace
	graph combine "dump/gender_w2.gph" "dump/age_w2.gph" "dump/edu_w2.gph" "dump/vote_w2.gph", title (Welle 2 Nov 2020) rows(4)
	graph save "dump/dist_w2.gph", replace
	graph combine "dump/gender_w3.gph" "dump/age_w3.gph" "dump/edu_w3.gph" "dump/vote_w3.gph", title (Welle 3 Feb 2021) rows(4)
	graph save "dump/dist_w3.gph", replace
	
	graph combine "dump/dist_w1.gph" "dump/dist_w2.gph" "dump/dist_w3.gph", col(3) ysize(10) xsize(9) iscale(.45)
	*graph save "figures/fig_0.gph", replace
	graph export "figures/fig_0.emf", replace
	graph export "figures/fig_0.pdf", replace
	
* multiple imputation			
			
* mi dataset erstellen
 mi set flong
 
*  missing tables
 #delimit ;
 mi misstable summ spectrust	
			difftrust				
			v_344
			covid19_measures
			govmeasures
			biggest_fear
			mediatrust_classic
			mediatrust_socialmedia
			dif_mediatrust
			auth
			pol_extr
			children_total
			children_small
			links_rechts			
			vot_int					
			v_342					
			healthstate				
			incomeloss				
			hh3andmore				
			male
			gender
			age	
			v_144
			v_145
			v_505_a					
			ohne_hauptschule		
			mittlere_reife			
			fachhochschulreife		
			abitur					
			studium	
			inf_7day_rel
			tot_30day_rel
			alq_18					
			alq_19					
			gdp_pc_17
			NUTS3
			bundesland;
			#delimit cr
			
 #delimit ;
 mi misstable patterns spectrust	
			difftrust				
			v_344
			covid19_measures
			govmeasures
			biggest_fear
			mediatrust_classic
			mediatrust_socialmedia
			dif_mediatrust
			auth
			pol_extr
			children_total
			children_small
			links_rechts					
			vot_int					
			v_342					
			healthstate				
			incomeloss				
			hh3andmore				
			male
			gender
			age	
			v_144
			v_145
			v_505_a					
			ohne_hauptschule		
			mittlere_reife			
			fachhochschulreife		
			abitur					
			studium	
			inf_7day_rel
			tot_30day_rel
			alq_18					
			alq_19					
			gdp_pc_17
			NUTS3
			bundesland;
			#delimit cr	
			
* register variables to be imputed
 #delimit ;
 mi register imputed spectrust	
			difftrust				
			v_344
			covid19_measures
			govmeasures
			biggest_fear
			mediatrust_classic
			mediatrust_socialmedia
			auth
			children_total
			children_small
			links_rechts					
			vot_int					
			v_342					
			healthstate				
			incomeloss				
			hh3andmore				
			gender
			age
			v_144
			v_145
			v_505_a					
			inf_7day_rel
			tot_30day_rel
			alq_18					
			alq_19					
			gdp_pc_17
			bundesland;
			#delimit cr	

			
* Littles Test of MAR
mcartest hh3andmore gender biggest_fear vot_int spectrust difftrust covid19_measures govmeasures mediatrust_classic mediatrust_socialmedia auth children_total children_small links_rechts incomeloss  v_342  v_505_a v_344 healthstate v_144 v_145 	inf_7day_rel tot_30day_rel alq_18 alq_19 gdp_pc_17 age
mcartest hh3andmore gender biggest_fear vot_int spectrust difftrust covid19_measures govmeasures mediatrust_classic mediatrust_socialmedia auth children_total children_small links_rechts incomeloss  v_342  v_505_a v_344 healthstate v_144 v_145	inf_7day_rel tot_30day_rel alq_18 alq_19 gdp_pc_17 age = i.welle	
			
			
* register variables as auxilliary variables (no missings)
mi register regular welle
			
			
* increase matsize
set matsize 2000


* Multiple imutation using the respective regression methods logit for binary, mlogit for nominal with more than two (or PMM if no convergence), ologit for ordinal and regress for metric with no limits, pmm for metric with clear min/max limits
* wave as factor variable included
* Graham (2009) suggests that cluster indicators can work well for as many as 35 indicator variables. Strategy 1 is best suited for data with few clusters and many observations within each cluster. see https://www.stata.com/support/faqs/statistics/clustering-and-mi-impute/
#delimit ;			
 mi impute chained 
		(logit) hh3andmore  
		(pmm, knn(10)) gender biggest_fear vot_int spectrust difftrust covid19_measures govmeasures mediatrust_classic mediatrust_socialmedia auth children_total children_small links_rechts incomeloss bundesland
		(ologit) v_342  v_505_a v_344 healthstate v_144 v_145
		(truncreg, ll(0))  inf_7day_rel tot_30day_rel alq_18 alq_19 gdp_pc_17
		(truncreg, ll(16) ul(100)) age
		= i.welle, add(10) rseed(1492)   dots noisily augment;
#delimit cr				
	save "data\mi_corona_panel_long2.dta", replace		


**** Calculate Raking Weights based on gender, agegroup, state and highest education
	clear all
	use "data\mi_corona_panel_long2.dta"
	replace pol_extr = abs(6-links_rechts)
	save "data\mi_corona_panel_long2.dta", replace
egen age_group = cut(age), at(16 ,20, 30, 40, 50, 60, 70, 80, 110)	 label 
table age_group

gen male_2 = gender
replace male_2 = 2 if gender == 3 
	
	* highest educational attainment 3 level
	recode v_505_a (1=1) (2=2) (3/5=3), gen(edu_3)
	label define edu_3 1 "low" 2 "middle" 3 "high"
	label values edu_3 edu_3
	label variable edu_3					"educational attainment (low/middle/high)"

* Basisgewicht = 1  generieren
gen wt = 1

	* Vorgehen nach : https://www.stata-press.com/books/sw-preview.pdf ab S. 58
	* wichtig! nicht die exakten Populationsgrößen verwenden, sondern gerundet auf tausend (dabei auf gleiche Anzahl an totals achten!)
	* Mit zu großen Zahlen kommt svycal nicht zurecht
	* totals for raking from file weights_calculation.xlsx

	* only wave 1
	#delimit ; 
	svycal rake  i.bundesland i.age_group  i.male_2 i.edu_3 [pw=wt] if id_alle_3_wellen !=. & welle == 1, gen(rake_wt_1) ll(0.1) ul(10) tolerance(0.01) 
	totals( _cons=70976
			1.bundesland	=	9420
			2.bundesland 	=	11178
			3.bundesland	=	3105
			4.bundesland	= 	2161
			5.bundesland	=	585
			6.bundesland	= 	1566
			7.bundesland	=	5337
			8.bundesland	= 	1392
			9.bundesland	= 	6816
			10.bundesland	=	15290
			11.bundesland	=	3502
			12.bundesland	=	862
			13.bundesland	= 	3504
			14.bundesland	=	1921
			15.bundesland	= 	2483
			16.bundesland	=	1854
			0.age_group		=	3251
			1.age_group		=	9801
			2.age_group		=	10647
			3.age_group		=	10426
			4.age_group		=	13474
			5.age_group		=	10302
			6.age_group		=	7686
			7.age_group		=	5389	
			1.male_2		=	34779
			2.male_2		=	36197
			1.edu_3			=	24929
			2.edu_3			=	22040
			3.edu_3			=	24007)		;
#delimit cr	

	* only wave 2
	#delimit ; 
	svycal rake  i.bundesland i.age_group  i.male_2 i.edu_3 [pw=wt] if id_alle_3_wellen !=. & welle == 2, gen(rake_wt_2) ll(0.1) ul(10) tolerance(0.01) 
	totals( _cons=70976
			1.bundesland	=	9420
			2.bundesland 	=	11178
			3.bundesland	=	3105
			4.bundesland	= 	2161
			5.bundesland	=	585
			6.bundesland	= 	1566
			7.bundesland	=	5337
			8.bundesland	= 	1392
			9.bundesland	= 	6816
			10.bundesland	=	15290
			11.bundesland	=	3502
			12.bundesland	=	862
			13.bundesland	= 	3504
			14.bundesland	=	1921
			15.bundesland	= 	2483
			16.bundesland	=	1854
			0.age_group		=	3251
			1.age_group		=	9801
			2.age_group		=	10647
			3.age_group		=	10426
			4.age_group		=	13474
			5.age_group		=	10302
			6.age_group		=	7686
			7.age_group		=	5389	
			1.male_2		=	34779
			2.male_2		=	36197
			1.edu_3			=	24929
			2.edu_3			=	22040
			3.edu_3			=	24007)		;
#delimit cr	

	* only wave 3
	#delimit ; 
	svycal rake  i.bundesland i.age_group  i.male_2 i.edu_3 [pw=wt] if id_alle_3_wellen !=. & welle == 3, gen(rake_wt_3) ll(0.1) ul(10) tolerance(0.01) 
	totals( _cons=70976
			1.bundesland	=	9420
			2.bundesland 	=	11178
			3.bundesland	=	3105
			4.bundesland	= 	2161
			5.bundesland	=	585
			6.bundesland	= 	1566
			7.bundesland	=	5337
			8.bundesland	= 	1392
			9.bundesland	= 	6816
			10.bundesland	=	15290
			11.bundesland	=	3502
			12.bundesland	=	862
			13.bundesland	= 	3504
			14.bundesland	=	1921
			15.bundesland	= 	2483
			16.bundesland	=	1854
			0.age_group		=	3251
			1.age_group		=	9801
			2.age_group		=	10647
			3.age_group		=	10426
			4.age_group		=	13474
			5.age_group		=	10302
			6.age_group		=	7686
			7.age_group		=	5389	
			1.male_2		=	34779
			2.male_2		=	36197
			1.edu_3			=	24929
			2.edu_3			=	22040
			3.edu_3			=	24007)		;
#delimit cr	

	* all 3 waves
	#delimit ; 
	svycal rake  i.bundesland i.age_group  i.male_2 i.edu_3 [pw=wt] if id_alle_3_wellen !=. , gen(rake_wt_1_3) ll(0.1) ul(10) tolerance(0.01) 
	totals( _cons=70976
			1.bundesland	=	9420
			2.bundesland 	=	11178
			3.bundesland	=	3105
			4.bundesland	= 	2161
			5.bundesland	=	585
			6.bundesland	= 	1566
			7.bundesland	=	5337
			8.bundesland	= 	1392
			9.bundesland	= 	6816
			10.bundesland	=	15290
			11.bundesland	=	3502
			12.bundesland	=	862
			13.bundesland	= 	3504
			14.bundesland	=	1921
			15.bundesland	= 	2483
			16.bundesland	=	1854
			0.age_group		=	3251
			1.age_group		=	9801
			2.age_group		=	10647
			3.age_group		=	10426
			4.age_group		=	13474
			5.age_group		=	10302
			6.age_group		=	7686
			7.age_group		=	5389	
			1.male_2		=	34779
			2.male_2		=	36197
			1.edu_3			=	24929
			2.edu_3			=	22040
			3.edu_3			=	24007)		;
#delimit cr	


save "data\mi_corona_panel_long2.dta", replace





* table with descriptives
clear all
use "data\mi_corona_panel_long2.dta"
bysort welle: outreg2 using "tables\table_1" if id_alle_3_wellen != . & _mi_m >= 1  , word label replace sum(log) eqkeep(mean sd) keep(spectrust difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17)
	* + percentages of categori
	bysort welle: tab vot_int  if id_alle_3_wellen != . & _mi_m >= 1
	bysort welle: tab gender  if id_alle_3_wellen != . & _mi_m >= 1
	bysort welle: tab v_505_a  if id_alle_3_wellen != . & _mi_m >= 1
	bysort welle: tab biggest_fear  if id_alle_3_wellen != . & _mi_m >= 1

*** descriptive statistics of spectrust & difftrust		
	clear all
	use "data\mi_corona_panel_long2.dta"
	replace pol_extr = abs(6-links_rechts)
	save "data\mi_corona_panel_long2.dta", replace

label define welle 1 "Mai 2020" 2 "Nov 2020" 3 "Feb 2021"	
label values welle welle	
	
	

* by party
collapse (mean) spectrust_mean = spectrust difftrust_mean = difftrust (semean) spectrust_se = spectrust difftrust_se = difftrust if id_alle_3_wellen != ., by(welle vot_int)
gen spectrust_low = spectrust_mean - 1.96*spectrust_se
gen spectrust_high = spectrust_mean + 1.96*spectrust_se
gen difftrust_low = difftrust_mean - 1.96*difftrust_se
gen difftrust_high = difftrust_mean + 1.96*difftrust_se

set scheme plotplain

* spectrust by party
#delimit ;
twoway 	(line spectrust_mean welle if vot_int == 1, 					lcolor(black) lpattern(solid)) 
		(rarea spectrust_low spectrust_high welle if vot_int == 1, 	lcolor(black) lpattern(solid) )
		(line spectrust_mean welle if vot_int == 2, 					lcolor(red) lpattern(solid))
		(rarea spectrust_low spectrust_high welle if vot_int == 2, 	lcolor(red) lpattern(solid) )
		(line spectrust_mean welle if vot_int == 3, 					lcolor(purple) lpattern(solid))
		(rarea spectrust_low spectrust_high welle if vot_int == 3, 	lcolor(purple) lpattern(solid) )
		(line spectrust_mean welle if vot_int == 4, 					lcolor(green) lpattern(solid))
		(rarea spectrust_low spectrust_high welle if vot_int == 4, 	lcolor(green) lpattern(solid) )
		(line spectrust_mean welle if vot_int == 5, 					lcolor(yellow) lpattern(solid))
		(rarea spectrust_low spectrust_high welle if vot_int == 5, 	lcolor(yellow) lpattern(solid) )
		(line spectrust_mean welle if vot_int == 6, 					lcolor(ltblue) lpattern(solid))
		(rarea spectrust_low spectrust_high welle if vot_int == 6, 	lcolor(ltblue) lpattern(solid) )
		(line spectrust_mean welle if vot_int == 7, 					lcolor(brown) lpattern(solid))
		(rarea spectrust_low spectrust_high welle if vot_int == 7, 	lcolor(brown) lpattern(solid) )
		(line spectrust_mean welle if vot_int == 8, 					lcolor(grey) lpattern(dash))
		(rarea spectrust_low spectrust_high welle if vot_int == 8, 	lcolor(grey) lpattern(solid) )
		(line spectrust_mean welle if vot_int == 9, 					lcolor(grey) lpattern(shortdash_dot))
		(rarea spectrust_low spectrust_high welle if vot_int == 9, 	lcolor(grey) lpattern(solid) )
		,xlabel(#3 ,valuelabel angle(30) labsize(mediumsmall))
		ylabel(1(1)5, labsize(mediumsmall))
		legend(order(1 "CDU/CSU" 3 "SPD" 5 "Linke" 7 "Grüne" 9 "FDP" 11 "AfD" 13 "Protestpartei" 15 "andere Partei" 17 "würde nicht wählen")rows(2))
		title("Spezifisches Vertrauen" "(Mittelwert + 95% CI)")
		xtitle("");
#delimit cr	
graph save "dump\spectrust_by_party.gph", replace
graph export "dump\spectrust_by_party.pdf", replace
graph export "dump\spectrust_by_party.emf", replace

* difftrust by party
#delimit ;
twoway 	(line difftrust_mean welle if vot_int == 1, 					lcolor(black) lpattern(solid)) 
		(rspike difftrust_low difftrust_high welle if vot_int == 1, 	lcolor(black) lpattern(solid) )
		(line difftrust_mean welle if vot_int == 2, 					lcolor(red) lpattern(solid))
		(rspike difftrust_low difftrust_high welle if vot_int == 2, 	lcolor(red) lpattern(solid) )
		(line difftrust_mean welle if vot_int == 3, 					lcolor(purple) lpattern(solid))
		(rspike difftrust_low difftrust_high welle if vot_int == 3, 	lcolor(purple) lpattern(solid) )
		(line difftrust_mean welle if vot_int == 4, 					lcolor(green) lpattern(solid))
		(rspike difftrust_low difftrust_high welle if vot_int == 4, 	lcolor(green) lpattern(solid) )
		(line difftrust_mean welle if vot_int == 5, 					lcolor(yellow) lpattern(solid))
		(rspike difftrust_low difftrust_high welle if vot_int == 5, 	lcolor(yellow) lpattern(solid) )
		(line difftrust_mean welle if vot_int == 6, 					lcolor(ltblue) lpattern(solid))
		(rspike difftrust_low difftrust_high welle if vot_int == 6, 	lcolor(ltblue) lpattern(solid) )
		(line difftrust_mean welle if vot_int == 7, 					lcolor(brown) lpattern(solid))
		(rspike difftrust_low difftrust_high welle if vot_int == 7, 	lcolor(brown) lpattern(solid) )
		(line difftrust_mean welle if vot_int == 8, 					lcolor(grey) lpattern(dash))
		(rspike difftrust_low difftrust_high welle if vot_int == 8, 	lcolor(grey) lpattern(solid) )
		(line difftrust_mean welle if vot_int == 9, 					lcolor(grey) lpattern(shortdash_dot))
		(rspike difftrust_low difftrust_high welle if vot_int == 9, 	lcolor(grey) lpattern(solid) )
		,xlabel(#3 ,valuelabel angle(30) labsize(mediumsmall))
		ylabel(1(1)5, labsize(mediumsmall))
		legend(order(1 "CDU/CSU" 3 "SPD" 5 "Linke" 7 "Grüne" 9 "FDP" 11 "AfD" 13 "Protestpartei" 15 "andere Partei" 17 "würde nicht wählen")rows(2))
		title("Diffuses Vertrauen" "(Mittelwert + 95% CI)")
		xtitle("");
#delimit cr	
graph save "dump\difftrust_by_party.gph", replace
graph export "dump\difftrust_by_party.pdf", replace

grc1leg "dump\spectrust_by_party.gph" "dump\difftrust_by_party.gph"
graph export "dump\fig_1_color.pdf", replace
graph export "dump\fig_1_color.emf", replace

** GRAUSTUFEN
* spectrust by party
#delimit ;
twoway 	(line spectrust_mean welle if vot_int == 1, 					lwidth(medthick) lcolor(black) lpattern(solid)) 
		(line spectrust_mean welle if vot_int == 2, 					lwidth(medthick) lcolor(gs5) lpattern(solid))
		(line spectrust_mean welle if vot_int == 3, 					lwidth(medthick) lcolor(gs10) lpattern(solid))
		(line spectrust_mean welle if vot_int == 4, 					lwidth(medthick) lcolor(gs10) lpattern(longdash_dot))
		(line spectrust_mean welle if vot_int == 5, 					lwidth(medthick) lcolor(black) lpattern(dash))
		(line spectrust_mean welle if vot_int == 6, 					lwidth(medthick) lcolor(gs5) lpattern(dash))
		(line spectrust_mean welle if vot_int == 7, 					lwidth(medthick) lcolor(gs10) lpattern(dash))
		(line spectrust_mean welle if vot_int == 8, 					lwidth(medthick) lcolor(gs5) lpattern(shortdash_dot))
		(line spectrust_mean welle if vot_int == 9, 					lwidth(medthick) lcolor(gs12) lpattern(shortdash_dot))
		,xlabel(#3 ,valuelabel angle(30) labsize(mediumsmall))
		ylabel(1(1)4, labsize(mediumsmall))
		legend(order(1 "CDU/CSU" 2 "SPD" 3 "Linke" 4 "Grüne" 5 "FDP" 6 "AfD" 7 "Protestpartei" 8 "andere Partei" 9 "würde nicht wählen")rows(2))
		title("Spezifisches Politikvertrauen")
		xtitle("")
		ytitle("");
#delimit cr	
gr_edit .legend.plotregion1.key[1].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[2].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[3].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[4].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[5].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[6].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[7].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[8].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[9].xsz.editstyle 7 editcopy
graph save "dump\spectrust_by_party_grey.gph", replace


* difftrust by party
#delimit ;
twoway 	(line difftrust_mean welle if vot_int == 1, 					lwidth(medthick) lcolor(black) lpattern(solid)) 
		(line difftrust_mean welle if vot_int == 2, 					lwidth(medthick) lcolor(gs5) lpattern(solid))
		(line difftrust_mean welle if vot_int == 3, 					lwidth(medthick) lcolor(gs10) lpattern(solid))
		(line difftrust_mean welle if vot_int == 4, 					lwidth(medthick) lcolor(gs10) lpattern(longdash_dot))
		(line difftrust_mean welle if vot_int == 5, 					lwidth(medthick) lcolor(black) lpattern(dash))
		(line difftrust_mean welle if vot_int == 6, 					lwidth(medthick) lcolor(gs5) lpattern(dash))
		(line difftrust_mean welle if vot_int == 7, 					lwidth(medthick) lcolor(gs10) lpattern(dash))
		(line difftrust_mean welle if vot_int == 8, 					lwidth(medthick) lcolor(gs5) lpattern(shortdash_dot))
		(line difftrust_mean welle if vot_int == 9, 					lwidth(medthick) lcolor(gs12) lpattern(shortdash_dot))
		,xlabel(#3 ,valuelabel angle(30) labsize(mediumsmall))
		ylabel(1(1)4, labsize(mediumsmall))
		legend(order(1 "CDU/CSU" 2 "SPD" 3 "Linke" 4 "Grüne" 5 "FDP" 6 "AfD" 7 "Protestpartei" 8 "andere Partei" 9 "würde nicht wählen")rows(2))
		title("Generalisiertes Politikvertrauen")
		xtitle("")
		ytitle("");
#delimit cr	
gr_edit .legend.plotregion1.key[1].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[2].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[3].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[4].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[5].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[6].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[7].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[8].xsz.editstyle 7 editcopy
gr_edit .legend.plotregion1.key[9].xsz.editstyle 7 editcopy
graph save "dump\difftrust_by_party_grey.gph", replace


grc1leg "dump\spectrust_by_party_grey.gph" "dump\difftrust_by_party_grey.gph"
graph save "figures\fig_1.gph", replace
graph export "figures\fig_1.pdf", replace
graph export "figures\fig_1.emf", replace








* by mediatrust_classic
	clear all
	use "data\mi_corona_panel_long2.dta"
	replace pol_extr = abs(6-links_rechts)
	save "data\mi_corona_panel_long2.dta", replace

	gen mediatrust_classic_3 = .
	replace mediatrust_classic_3 = 1 if mediatrust_classic >=0 & mediatrust_classic < 0.33
	replace mediatrust_classic_3 = 2 if mediatrust_classic >=0.33 & mediatrust_classic < 0.66
	replace mediatrust_classic_3 = 3 if mediatrust_classic >= 0.66 & mediatrust_classic <= 1
	 
	collapse (mean) spectrust_mean = spectrust difftrust_mean = difftrust (semean) spectrust_se = spectrust difftrust_se = difftrust if id_alle_3_wellen != ., by(welle mediatrust_classic_3)
	gen spectrust_low = spectrust_mean - 1.96*spectrust_se
	gen spectrust_high = spectrust_mean + 1.96*spectrust_se
	gen difftrust_low = difftrust_mean - 1.96*difftrust_se
	gen difftrust_high = difftrust_mean + 1.96*difftrust_se

	label define welle 1 "Mai 2020" 2 "Nov 2020" 3 "Feb 2021"	
	label values welle welle	

	
* spectrust by mediatrust_classic_3
#delimit ;
twoway 	(line spectrust_mean welle if mediatrust_classic_3 == 1, 					lcolor(red) lpattern(shortdash)) 
		(rspike spectrust_low spectrust_high welle if mediatrust_classic_3 == 1, 	lcolor(red) lpattern(solid) )
		(line spectrust_mean welle if mediatrust_classic_3 == 2, 					lcolor(blue) lpattern(dash))
		(rspike spectrust_low spectrust_high welle if mediatrust_classic_3 == 2, 	lcolor(blue) lpattern(solid) )
		(line spectrust_mean welle if mediatrust_classic_3 == 3, 					lcolor(black) lpattern(solid))
		(rspike spectrust_low spectrust_high welle if mediatrust_classic_3 == 3, 	lcolor(black) lpattern(solid) )
		,xlabel(#3 ,valuelabel angle(30) labsize(mediumsmall))
		ylabel(1(1)5, labsize(mediumsmall))
		legend(order(1 "niedrig" 3 "mittel" 5 "hoch" ) rows(1) title("Vertrauen in Informationsquelle", size(small)))
		ytitle("")
		title(Klassische Informationsquellen)
		xtitle("");
#delimit cr	
graph save "dump\spectrust_by_mediatrust_classic.gph", replace
graph export "dump\spectrust_by_mediatrust_classic.pdf", replace
graph export "dump\spectrust_by_mediatrust_classic.emf", replace


* difftrust by mediatrust_classic_3
#delimit ;
twoway 	(line difftrust_mean welle if mediatrust_classic_3 == 1, 					lcolor(red) lpattern(shortdash)) 
		(rspike difftrust_low difftrust_high welle if mediatrust_classic_3 == 1, 	lcolor(red) lpattern(solid) )
		(line difftrust_mean welle if mediatrust_classic_3 == 2, 					lcolor(blue) lpattern(dash))
		(rspike difftrust_low difftrust_high welle if mediatrust_classic_3 == 2, 	lcolor(blue) lpattern(solid) )
		(line difftrust_mean welle if mediatrust_classic_3 == 3, 					lcolor(black) lpattern(solid))
		(rspike difftrust_low difftrust_high welle if mediatrust_classic_3 == 3, 	lcolor(black) lpattern(solid) )
		,xlabel(#3 ,valuelabel angle(30) labsize(mediumsmall))
		ylabel(1(1)5, labsize(mediumsmall))
		legend(title("Vertrauen in Informationsquelle") order(1 "niedrig" 3 "mittel" 5 "hoch" ))
		ytitle("")
		title(Klassische Informationsquellen)
		xtitle("");
#delimit cr	
graph save "dump\difftrust_by_mediatrust_classic.gph", replace
graph export "dump\difftrust_by_mediatrust_classic.pdf", replace
graph export "dump\difftrust_by_mediatrust_classic.emf", replace

* by mediatrust_socialmedia
	clear all
	use "data\mi_corona_panel_long2.dta"
	replace pol_extr = abs(6-links_rechts)
	save "data\mi_corona_panel_long2.dta", replace

	gen mediatrust_socialmedia_3 = .
	replace mediatrust_socialmedia_3 = 1 if mediatrust_socialmedia >=0 & mediatrust_socialmedia < 0.33
	replace mediatrust_socialmedia_3 = 2 if mediatrust_socialmedia >=0.33 & mediatrust_socialmedia < 0.66
	replace mediatrust_socialmedia_3 = 3 if mediatrust_socialmedia >= 0.66 & mediatrust_socialmedia <= 1
	 
	collapse (mean) spectrust_mean = spectrust difftrust_mean = difftrust (semean) spectrust_se = spectrust difftrust_se = difftrust if id_alle_3_wellen != ., by(welle mediatrust_socialmedia_3)
	gen spectrust_low = spectrust_mean - 1.96*spectrust_se
	gen spectrust_high = spectrust_mean + 1.96*spectrust_se
	gen difftrust_low = difftrust_mean - 1.96*difftrust_se
	gen difftrust_high = difftrust_mean + 1.96*difftrust_se

	label define welle 1 "Mai 2020" 2 "Nov 2020" 3 "Feb 2021"	
	label values welle welle	
	
	
* spectrust by mediatrust_socialmedia_3
#delimit ;
twoway 	(line spectrust_mean welle if mediatrust_socialmedia_3 == 1, 					lcolor(red) lpattern(shortdash)) 
		(rspike spectrust_low spectrust_high welle if mediatrust_socialmedia_3 == 1, 	lcolor(red) lpattern(solid) )
		(line spectrust_mean welle if mediatrust_socialmedia_3 == 2, 					lcolor(blue) lpattern(dash))
		(rspike spectrust_low spectrust_high welle if mediatrust_socialmedia_3 == 2, 	lcolor(blue) lpattern(solid) )
		(line spectrust_mean welle if mediatrust_socialmedia_3 == 3, 					lcolor(black) lpattern(solid))
		(rspike spectrust_low spectrust_high welle if mediatrust_socialmedia_3 == 3, 	lcolor(black) lpattern(solid) )
		,xlabel(#3 ,valuelabel angle(30) labsize(mediumsmall))
		ylabel(1(1)5, labsize(mediumsmall))
		legend(order(1 "niedriges Vertrauen in soziale Medien" 3 "mittleres Vertrauen in soziale Medien" 5 "hohes Vertrauen in soziale Medien" ))
		ytitle("")
		title(Soziale Medien)
		xtitle("");
#delimit cr	
graph save "dump\spectrust_by_mediatrust_socialmedia.gph", replace
graph export "dump\spectrust_by_mediatrust_socialmedia.pdf", replace
graph export "dump\spectrust_by_mediatrust_socialmedia.emf", replace


* difftrust by mediatrust_socialmedia_3
#delimit ;
twoway 	(line difftrust_mean welle if mediatrust_socialmedia_3 == 1, 					lcolor(red) lpattern(shortdash)) 
		(rspike difftrust_low difftrust_high welle if mediatrust_socialmedia_3 == 1, 	lcolor(red) lpattern(solid) )
		(line difftrust_mean welle if mediatrust_socialmedia_3 == 2, 					lcolor(blue) lpattern(dash))
		(rspike difftrust_low difftrust_high welle if mediatrust_socialmedia_3 == 2, 	lcolor(blue) lpattern(solid) )
		(line difftrust_mean welle if mediatrust_socialmedia_3 == 3, 					lcolor(black) lpattern(solid))
		(rspike difftrust_low difftrust_high welle if mediatrust_socialmedia_3 == 3, 	lcolor(black) lpattern(solid) )
		,xlabel(#3 ,valuelabel angle(30) labsize(mediumsmall))
		ylabel(1(1)5, labsize(mediumsmall))
		legend(order(1 "niedriges Vertrauen in soziale Medien" 3 "mittleres Vertrauen in soziale Medien" 5 "hohes Vertrauen in soziale Medien" ))
		ytitle("")
		title(Soziale Medien)
		xtitle("");
#delimit cr	
graph save "dump\difftrust_by_mediatrust_socialmedia.gph", replace
graph export "dump\difftrust_by_mediatrust_socialmedia.pdf", replace
graph export "dump\difftrust_by_mediatrust_socialmedia.emf", replace

grc1leg "dump\spectrust_by_mediatrust_classic.gph" "dump\spectrust_by_mediatrust_socialmedia.gph", title("Spezifisches Politikvertrauen" "(Mittelwert + 95% CI)")
graph save "dump\spectrust_media.gph", replace

grc1leg "dump\difftrust_by_mediatrust_classic.gph"  "dump\difftrust_by_mediatrust_socialmedia.gph", title("Generalisiertes Politikvertrauen" "(Mittelwert + 95% CI)")
graph save "dump\difftrust_media.gph", replace

grc1leg "dump\spectrust_media.gph" "dump\difftrust_media.gph"
graph export "figures\fig_2_color.pdf", replace
graph export "figures\fig_2_color.emf", replace


**GRAUSTUFEN

* by mediatrust_classic
	clear all
	use "data\mi_corona_panel_long2.dta"
	replace pol_extr = abs(6-links_rechts)
	save "data\mi_corona_panel_long2.dta", replace

	gen mediatrust_classic_3 = .
	replace mediatrust_classic_3 = 1 if mediatrust_classic >=0 & mediatrust_classic < 0.33
	replace mediatrust_classic_3 = 2 if mediatrust_classic >=0.33 & mediatrust_classic < 0.66
	replace mediatrust_classic_3 = 3 if mediatrust_classic >= 0.66 & mediatrust_classic <= 1
	 
	collapse (mean) spectrust_mean = spectrust difftrust_mean = difftrust (semean) spectrust_se = spectrust difftrust_se = difftrust if id_alle_3_wellen != ., by(welle mediatrust_classic_3)
	gen spectrust_low = spectrust_mean - 1.96*spectrust_se
	gen spectrust_high = spectrust_mean + 1.96*spectrust_se
	gen difftrust_low = difftrust_mean - 1.96*difftrust_se
	gen difftrust_high = difftrust_mean + 1.96*difftrust_se

	label define welle 1 "Mai 2020" 2 "Nov 2020" 3 "Feb 2021"	
	label values welle welle	

* spectrust by mediatrust_classic_3
#delimit ;
twoway 	(line spectrust_mean welle if mediatrust_classic_3 == 1, 					lwidth(medthick) lcolor(black) lpattern(shortdash)) 
		(line spectrust_mean welle if mediatrust_classic_3 == 2, 					lwidth(medthick) lcolor(gs8) lpattern(dash))
		(line spectrust_mean welle if mediatrust_classic_3 == 3, 					lwidth(medthick) lcolor(black) lpattern(solid))
		,xlabel(#3 ,valuelabel angle(30) labsize(mediumsmall))
		ylabel(1(1)5, labsize(mediumsmall))
		legend(order(1 "niedrig" 2 "mittel" 3 "hoch" ) rows(1) title("Vertrauen in Informationsquelle", size(small)))
		ytitle("")
		title(Klassische Informationsquellen)
		xtitle("");
#delimit cr	
graph save "dump\spectrust_by_mediatrust_classic_grey.gph", replace
graph export "dump\spectrust_by_mediatrust_classic_grey.pdf", replace
graph export "dump\spectrust_by_mediatrust_classic_grey.emf", replace


* difftrust by mediatrust_classic_3
#delimit ;
twoway 	(line difftrust_mean welle if mediatrust_classic_3 == 1, 					lwidth(medthick) lcolor(black) lpattern(shortdash)) 
		(line difftrust_mean welle if mediatrust_classic_3 == 2, 					lwidth(medthick) lcolor(gs8) lpattern(dash))
		(line difftrust_mean welle if mediatrust_classic_3 == 3, 					lwidth(medthick) lcolor(black) lpattern(solid))
		,xlabel(#3 ,valuelabel angle(30) labsize(mediumsmall))
		ylabel(1(1)5, labsize(mediumsmall))
		legend(title("Vertrauen in Informationsquelle") order(1 "niedrig" 3 "mittel" 5 "hoch" ))
		ytitle("")
		title(Klassische Informationsquellen)
		xtitle("");
#delimit cr	
graph save "dump\difftrust_by_mediatrust_classic_grey.gph", replace
graph export "dump\difftrust_by_mediatrust_classic_grey.pdf", replace
graph export "dump\difftrust_by_mediatrust_classic_grey.emf", replace

* by mediatrust_socialmedia
	clear all
	use "data\mi_corona_panel_long2.dta"
	replace pol_extr = abs(6-links_rechts)
	save "data\mi_corona_panel_long2.dta", replace

	gen mediatrust_socialmedia_3 = .
	replace mediatrust_socialmedia_3 = 1 if mediatrust_socialmedia >=0 & mediatrust_socialmedia < 0.33
	replace mediatrust_socialmedia_3 = 2 if mediatrust_socialmedia >=0.33 & mediatrust_socialmedia < 0.66
	replace mediatrust_socialmedia_3 = 3 if mediatrust_socialmedia >= 0.66 & mediatrust_socialmedia <= 1
	 
	collapse (mean) spectrust_mean = spectrust difftrust_mean = difftrust (semean) spectrust_se = spectrust difftrust_se = difftrust if id_alle_3_wellen != ., by(welle mediatrust_socialmedia_3)
	gen spectrust_low = spectrust_mean - 1.96*spectrust_se
	gen spectrust_high = spectrust_mean + 1.96*spectrust_se
	gen difftrust_low = difftrust_mean - 1.96*difftrust_se
	gen difftrust_high = difftrust_mean + 1.96*difftrust_se

	label define welle 1 "Mai 2020" 2 "Nov 2020" 3 "Feb 2021"	
	label values welle welle	
	
	
* spectrust by mediatrust_socialmedia_3
#delimit ;
twoway 	(line spectrust_mean welle if mediatrust_socialmedia_3 == 1, 					lwidth(medthick) lcolor(black) lpattern(shortdash)) 
		(line spectrust_mean welle if mediatrust_socialmedia_3 == 2, 					lwidth(medthick) lcolor(gs8) lpattern(dash))
		(line spectrust_mean welle if mediatrust_socialmedia_3 == 3, 					lwidth(medthick) lcolor(black) lpattern(solid))
		,xlabel(#3 ,valuelabel angle(30) labsize(mediumsmall))
		ylabel(1(1)5, labsize(mediumsmall))
		legend(order(1 "niedriges Vertrauen in soziale Medien" 2 "mittleres Vertrauen in soziale Medien" 3 "hohes Vertrauen in soziale Medien" ))
		ytitle("")
		title(Soziale Medien)
		xtitle("");
#delimit cr	
graph save "dump\spectrust_by_mediatrust_socialmedia_grey.gph", replace
graph export "dump\spectrust_by_mediatrust_socialmedia_grey.pdf", replace
graph export "dump\spectrust_by_mediatrust_socialmedia_grey.emf", replace


* difftrust by mediatrust_socialmedia_3
#delimit ;
twoway 	(line difftrust_mean welle if mediatrust_socialmedia_3 == 1, 					lwidth(medthick) lcolor(black) lpattern(shortdash)) 
		(line difftrust_mean welle if mediatrust_socialmedia_3 == 2, 					lwidth(medthick) lcolor(gs8) lpattern(dash))
		(line difftrust_mean welle if mediatrust_socialmedia_3 == 3, 					lwidth(medthick) lcolor(black) lpattern(solid))
		,xlabel(#3 ,valuelabel angle(30) labsize(mediumsmall))
		ylabel(1(1)5, labsize(mediumsmall))
		legend(order(1 "niedriges Vertrauen in soziale Medien" 2 "mittleres Vertrauen in soziale Medien" 3 "hohes Vertrauen in soziale Medien" ))
		ytitle("")
		title(Soziale Medien)
		xtitle("");
#delimit cr	
graph save "dump\difftrust_by_mediatrust_socialmedia_grey.gph", replace
graph export "dump\difftrust_by_mediatrust_socialmedia_grey.pdf", replace
graph export "dump\difftrust_by_mediatrust_socialmedia_grey.emf", replace

grc1leg "dump\spectrust_by_mediatrust_classic_grey.gph" "dump\spectrust_by_mediatrust_socialmedia_grey.gph", title("Spezifisches Politikvertrauen" )
graph save "dump\spectrust_media_grey.gph", replace

grc1leg "dump\difftrust_by_mediatrust_classic_grey.gph"  "dump\difftrust_by_mediatrust_socialmedia_grey.gph", title("Generalisiertes Politikvertrauen" )
graph save "dump\difftrust_media_grey.gph", replace

grc1leg "dump\spectrust_media_grey.gph" "dump\difftrust_media_grey.gph"
graph export "figures\fig_2.pdf", replace
graph export "figures\fig_2.emf", replace



	
*** Regression Models	
*** cross section regressions for each wave explaining the level of poltrust	

clear all
use "data\mi_corona_panel_long2.dta"

* A) all cases	

// ** NOT WEIGHTED - not presented in article
// * wave 1
// mi svyset [pweight=rake_wt]
// mi estimate, post: svy : reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 1
// eststo m_1s 
//	
// * wave 2
// mi estimate , post: reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 2 
// eststo m_2s
//				
//			
// * wave 3
// mi estimate , post: reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 3 
// eststo m_3s
//
// * wave 1
// mi estimate , post: reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 1 
// eststo m_1d 
//	
//	
// * wave 2
// mi estimate , post: reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 2 
// eststo m_2d
//				
//			
// * wave 3
// mi estimate , post: reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 3 
// eststo m_3d
//	
// esttab m_1s m_2s m_3s m_1d m_2d m_3d  using "tables\table_1.rtf", label  starlevels(+ 0.10 * 0.05 ** 0.01) replace			




*** Regression models	
	clear all
	use "data\mi_corona_panel_long2.dta"
	replace pol_extr = abs(6-links_rechts)
	save "data\mi_corona_panel_long2.dta", replace

label define welle 1 "Mai 2020" 2 "Nov 2020" 3 "Feb 2021"	
label values welle welle				
* B) only subjects existent in all waves	
* specific trust - wave 1
mi svyset [pweight=rake_wt_1]
mi estimate, post: svy : reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 1 & id_alle_3_wellen != . 
eststo m_1sb 

	* Berechnung mean R2 nach https://www.stata.com/support/faqs/statistics/combine-results-with-multiply-imputed-data/
	mi query
	local M = r(M)
	scalar r2 = 0
	mi xeq 1/`M': svy : reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 1 & id_alle_3_wellen != . ; scalar r2 = r2 + e(r2)
	scalar r2 = r2/`M'
	di as txt "R2 over imputed data = " as res r2

	* Berechnung mean R2 using Fishers Z
	mi query
	local M = r(M)
	scalar r2 = 0
	mi xeq 1/`M': svy : reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 1 & id_alle_3_wellen != .  ; scalar r2 = r2 + atanh(sqrt(e(r2)))
	scalar r2 = tanh(r2/`M')^2
	di as txt "R2 using Fisher's z over imputed data = " as res r2

* specific trust - wave 2
mi svyset [pweight=rake_wt_2]
mi estimate, post: svy : reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 2 & id_alle_3_wellen != . 
eststo m_2sb


	* Berechnung mean R2 nach https://www.stata.com/support/faqs/statistics/combine-results-with-multiply-imputed-data/
	mi query
	local M = r(M)
	scalar r2 = 0
	mi xeq 1/`M': svy : reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 2 & id_alle_3_wellen != . ; scalar r2 = r2 + e(r2)
	scalar r2 = r2/`M'
	di as txt "R2 over imputed data = " as res r2

	* Berechnung mean R2 using Fishers Z
	mi query
	local M = r(M)
	scalar r2 = 0
	mi xeq 1/`M': svy : reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 2 & id_alle_3_wellen != .  ; scalar r2 = r2 + atanh(sqrt(e(r2)))
	scalar r2 = tanh(r2/`M')^2
	di as txt "R2 using Fisher's z over imputed data = " as res r2
				
* specific trust - wave 3
mi svyset [pweight=rake_wt_3]
mi estimate, post: svy : reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 3 & id_alle_3_wellen != . 
eststo m_3sb

	* Berechnung mean R2 nach https://www.stata.com/support/faqs/statistics/combine-results-with-multiply-imputed-data/
	mi query
	local M = r(M)
	scalar r2 = 0
	mi xeq 1/`M': svy : reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 3 & id_alle_3_wellen != . ; scalar r2 = r2 + e(r2)
	scalar r2 = r2/`M'
	di as txt "R2 over imputed data = " as res r2

	* Berechnung mean R2 using Fishers Z
	mi query
	local M = r(M)
	scalar r2 = 0
	mi xeq 1/`M': svy : reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 3 & id_alle_3_wellen != .  ; scalar r2 = r2 + atanh(sqrt(e(r2)))
	scalar r2 = tanh(r2/`M')^2
	di as txt "R2 using Fisher's z over imputed data = " as res r2


* generalized trust - wave 1
mi svyset [pweight=rake_wt_1]
mi estimate, post: svy : reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 1 & id_alle_3_wellen != . 
eststo m_1db 

	* Berechnung mean R2 nach https://www.stata.com/support/faqs/statistics/combine-results-with-multiply-imputed-data/
	mi query
	local M = r(M)
	scalar r2 = 0
	mi xeq 1/`M': svy : reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 1 & id_alle_3_wellen != . ; scalar r2 = r2 + e(r2)
	scalar r2 = r2/`M'
	di as txt "R2 over imputed data = " as res r2

	* Berechnung mean R2 using Fishers Z
	mi query
	local M = r(M)
	scalar r2 = 0
	mi xeq 1/`M': svy : reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 1 & id_alle_3_wellen != .  ; scalar r2 = r2 + atanh(sqrt(e(r2)))
	scalar r2 = tanh(r2/`M')^2
	di as txt "R2 using Fisher's z over imputed data = " as res r2	
	
* generalized trust -  wave 2
mi svyset [pweight=rake_wt_2]
mi estimate, post: svy : reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 2 & id_alle_3_wellen != . 
eststo m_2db

	* Berechnung mean R2 nach https://www.stata.com/support/faqs/statistics/combine-results-with-multiply-imputed-data/
	mi query
	local M = r(M)
	scalar r2 = 0
	mi xeq 1/`M': svy : reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 2 & id_alle_3_wellen != . ; scalar r2 = r2 + e(r2)
	scalar r2 = r2/`M'
	di as txt "R2 over imputed data = " as res r2

	* Berechnung mean R2 using Fishers Z
	mi query
	local M = r(M)
	scalar r2 = 0
	mi xeq 1/`M': svy : reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 2 & id_alle_3_wellen != .  ; scalar r2 = r2 + atanh(sqrt(e(r2)))
	scalar r2 = tanh(r2/`M')^2
	di as txt "R2 using Fisher's z over imputed data = " as res r2					
			
* generalized trust -  wave 3
mi svyset [pweight=rake_wt_3]
mi estimate, post: svy : reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 3 & id_alle_3_wellen != . 
eststo m_3db

	* Berechnung mean R2 nach https://www.stata.com/support/faqs/statistics/combine-results-with-multiply-imputed-data/
	mi query
	local M = r(M)
	scalar r2 = 0
	mi xeq 1/`M': svy : reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 3 & id_alle_3_wellen != . ; scalar r2 = r2 + e(r2)
	scalar r2 = r2/`M'
	di as txt "R2 over imputed data = " as res r2

	* Berechnung mean R2 using Fishers Z
	mi query
	local M = r(M)
	scalar r2 = 0
	mi xeq 1/`M': svy : reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 3 & id_alle_3_wellen != .  ; scalar r2 = r2 + atanh(sqrt(e(r2)))
	scalar r2 = tanh(r2/`M')^2
	di as txt "R2 using Fisher's z over imputed data = " as res r2		
	
esttab m_1sb m_2sb m_3sb m_1db m_2db m_3db  using "tables\table_A1.rtf", label  starlevels(+ 0.10 * 0.05 ** 0.01) replace	
*esttab m_1sb m_2sb m_3sb m_1db m_2db m_3db  using "tables\table_A1_beta.rtf",  beta label  starlevels(+ 0.10 * 0.05 ** 0.01) replace				

set scheme plottigblind
* coefplot
coefplot (m_1sb, label("Welle 1 (Mai 2020)")) (m_2sb, label("Welle 1 (Nov 2020)")) (m_3sb, label("Welle 3 (Feb 2021)")) , bylabel(Spezifisches Politikvertrauen) ///
									|| (m_1db)                 (m_2db)   (m_3db)            , bylabel(Generalisiertes Politikvertrauen)  ///
									|| , drop(_cons) xline(0)  keep(links_rechts mediatrust* 2.vot_int 3.vot_int 4.vot_int 5.vot_int 6.vot_int 7.vot_int 8.vot_int 9.vot_int) msymbol(d) mcolor(white) levels(99 95 90) ciopts(lwidth(1.3 1.3 1.3) lcolor(*.33 *.66 *1)) ///
																																				legend(caption(p < 0.01            p < 0.05            p < 0.1, size(vsmall)) ///
																																						order(	1 "          " 2 "         " 3 "      Welle 1 (Mai 2020)" ///
																																								5 "          " 6 "         " 7 "      Welle 2 (Nov 2020)" ///
																																								9 "          " 10 "         " 11 "      Welle 3 (Feb 2021)" ) size(vsmall) row(3)   ///
																																								symxsize(*1.1)) ///
									order(2.vot_int 3.vot_int 4.vot_int 5.vot_int 6.vot_int 7.vot_int 8.vot_int 9.vot_int links_rechts mediatrust_classic mediatrust_socialmedia) ///
									headings(2.vot_int = "{it: Sonntagsfrage} (Referenz: CDU/CSU)" mediatrust_classic = " ", wrap(20)) ///
							coeflabels(	mediatrust_classic = "Vertrauen in klassische Informationsquellen"  ///
								mediatrust_socialmedia = "Vertrauen in soziale Medien"						///
								links_rechts = "Politische Einstellung (Links = 0; Rechts = 1)"						///
								, wrap(28))																	
graph save "figures\fig_4_color.gph", replace							
graph export "figures\fig_4_color.pdf", replace
graph export "figures\fig_4_color.emf", replace

set scheme plotplain
* coefplot
coefplot (m_1sb, label("Welle 1 (Mai 2020)")) (m_2sb, label("Welle 1 (Nov 2020)")) (m_3sb, label("Welle 3 (Feb 2021)")) , bylabel(Spezifisches Politikvertrauen) ///
									|| (m_1db)                 (m_2db)   (m_3db)            , bylabel(Generalisiertes Politikvertrauen)  ///
									|| , drop(_cons) xline(0)  keep(links_rechts mediatrust* 2.vot_int 3.vot_int 4.vot_int 5.vot_int 6.vot_int 7.vot_int 8.vot_int 9.vot_int)  mcolor(black) levels(99 95 90) ciopts(lwidth(1.3 1.3 1.3) lcolor(gs15 gs10 gs6)) ///
																																				legend(	order(	4 "Welle 1 (Mai 2020)" 8 "Welle 2 (Nov 2020)" 12 "Welle 3 (Feb 2021)" ///
																																								5 "p < 0.01" 6 "p < 0.05" 7 "p < 0.1"  ) size(vsmall) row(1)   ///
																																								symxsize(*1.1)) ///
									order(2.vot_int 3.vot_int 4.vot_int 5.vot_int 6.vot_int 7.vot_int 8.vot_int 9.vot_int links_rechts mediatrust_classic mediatrust_socialmedia) ///
									headings(2.vot_int = "{it: Sonntagsfrage} (Referenz: CDU/CSU)" mediatrust_classic = " ", wrap(20)) ///
							coeflabels(	mediatrust_classic = "Vertrauen in klassische Informationsquellen"  ///
								mediatrust_socialmedia = "Vertrauen in soziale Medien"						///
								links_rechts = "Politische Einstellung (Links = 0; Rechts = 1)"						///
								, wrap(28))		
								
								
* coefplot
coefplot (m_1sb, label("Umfragewelle 1 (Mai 2020)")) (m_2sb, label("Umfragewelle 1 (Nov 2020)")) (m_3sb, label("Umfragewelle 3 (Feb 2021)")) , bylabel(Spezifisches Politikvertrauen) ///
									|| (m_1db)                 (m_2db)   (m_3db)            , bylabel(Generalisiertes Politikvertrauen)  ///
									|| , drop(_cons) xline(0)  keep(links_rechts mediatrust* 2.vot_int 3.vot_int 4.vot_int 5.vot_int 6.vot_int 7.vot_int 8.vot_int 9.vot_int)  mcolor(black) levels(95) ciopts(recast(rcap) lcolor(gs10)) ///
																																				legend(	order(	2 "Umfragewelle 1 (Mai 2020)" 4 "Umfragewelle 2 (Nov 2020)" 6 "Umfragewelle 3 (Feb 2021)" 1 "95%-Konfidenzintervall" ///
																																								) size(vsmall) row(1)   ///
																																								symxsize(*1.1)) ///
									order(links_rechts 2.vot_int 3.vot_int 4.vot_int 5.vot_int 6.vot_int 7.vot_int 8.vot_int 9.vot_int mediatrust_classic mediatrust_socialmedia  ) ///
									headings(2.vot_int = "{it: Sonntagsfrage} (Referenz: CDU/CSU)" mediatrust_classic = " ", wrap(20)) ///
							coeflabels(	mediatrust_classic = "Vertrauen in klassische Informationsquellen"  ///
								mediatrust_socialmedia = "Vertrauen in soziale Medien"						///
								links_rechts = "Politische Einstellung (Links = 0; Rechts = 1)"						///
								, wrap(28))									

graph save "figures\fig_4.gph", replace							
graph export "figures\fig_4.pdf", replace
graph export "figures\fig_4.emf", replace




****** VIF auf Basis der ungewichteten mi-Modelle
*** Regression models	
	clear all
	use "data\mi_corona_panel_long2.dta"
	replace pol_extr = abs(6-links_rechts)
	save "data\mi_corona_panel_long2.dta", replace

label define welle 1 "Mai 2020" 2 "Nov 2020" 3 "Feb 2021"	
label values welle welle				
* B) only subjects existent in all waves	
* specific trust - wave 1

quietly mi estimate: reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 1 & id_alle_3_wellen != . 
mivif

* specific trust - wave 2
quietly mi estimate: reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 2 & id_alle_3_wellen != . 
mivif

* specific trust - wave 3
quietly mi estimate: reg spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 3 & id_alle_3_wellen != . 
mivif


* generalized trust - wave 1
quietly mi estimate: reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 1 & id_alle_3_wellen != . 
mivif

* generalized trust -  wave 2
quietly mi estimate: reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 2 & id_alle_3_wellen != . 
mivif

* generalized trust -  wave 3
quietly mi estimate:  reg difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 3 & id_alle_3_wellen != . 
mivif


*** Regression models	
	clear all
	use "data\mi_corona_panel_long2.dta"
	replace pol_extr = abs(6-links_rechts)
	save "data\mi_corona_panel_long2.dta", replace
****** Betas		
mibeta  spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 1 & id_alle_3_wellen != . [pweight=rake_wt_1]
mibeta  spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 2 & id_alle_3_wellen != . [pweight=rake_wt_2]
mibeta  spectrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 3 & id_alle_3_wellen != . [pweight=rake_wt_3]
mibeta  difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 1 & id_alle_3_wellen != . [pweight=rake_wt_1]
mibeta  difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 2 & id_alle_3_wellen != . [pweight=rake_wt_2]
mibeta  difftrust v_344 covid19_measures govmeasures i.biggest_fear mediatrust_classic mediatrust_socialmedia v_144 v_145 auth children_small links_rechts i.vot_int v_342 healthstate incomeloss i.gender age i.v_505_a inf_7day_rel tot_30day_rel alq_19 gdp_pc_17 if welle == 3 & id_alle_3_wellen != . [pweight=rake_wt_3]

















